<?php
/**
 * 企业名片
 * User: zal
 * Date: 2016/4/15
 * Time: 10:37
 */

namespace Api\Controller;
use Api\Controller\BaseController;

class CompanyController extends BaseController {

    public function index(){
        $companyModel=M('Company');
        $page=I('get.page','1'); //页码
        $size=I('get.size','10'); //显示数目
        $keyword=I('get.keyword','');
        $scid=I('get.scid','');
        $order=I("get.order",'addtime');
        $map=$data=array();
        if(!empty($keyword)){
            $map["co.company_name"]=array("like","%$keyword%");
        }

        if(!empty($scid)){
            $map["co.scid"]=$scid;
        }

        $limit_txt="";
        if($page>=1){
            $limit_txt=$size * ($page - 1).",".$size;
        }else{
            $limit_txt=$size;
        }

        $companyList=$companyModel->join('as co left join zsf_shop_category as sc on co.sc_id=sc.sc_id ' )
            ->field("co.id,co.company_name,co.addrss,co.tel,co.icon,co.lng,co.lat,co.addtime,sc.name")
            ->where($map)->order('id desc')->limit($limit_txt)->select();
        $data["data"]=$companyList;
        $data["code"]=200;
        $data["msg"]='ok';
        $this->ajaxReturn($data,'JSON');
    }

}